<%-- 
    Document   : addasklist
    Created on : 2016-9-5, 21:09:28
    Author     : 52461
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include  file="../link.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link href="${base}/css/bootstrap.css" rel="stylesheet">
        <link href="${base}/css/font-awesome.css" rel="stylesheet">
        <link href="${base}/css/material-kit.css" rel="stylesheet">
        <link href="${base}/css/bootstrap-material-datetimepicker.css" rel="stylesheet">
        <link href="${base}/css/nprogress.css" rel="stylesheet">

        <script type="text/javascript" src="${base}/js/jquery-1.9.1.js"></script>
        <script type="text/javascript" src="${base}/js/nprogress.js"></script>
        <script type="text/javascript" src="${base}/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="${base}/js/material.min.js"></script>
        <script type="text/javascript" src="${base}/js/material-kit.js"></script>
        <script type="text/javascript" src="${base}/js/moment-with-locales.min.js"></script>
        <script type="text/javascript" src="${base}/js/bootstrap-material-datetimepicker.js"></script>


        <script type="text/javascript" src="${base}/js/angular/angular.min.js"></script>
        <script type="text/javascript" src="${base}/js/mi.js"></script>
        <script type="text/javascript" src="${base}/js/angular/ui-bootstrap-tpls-0.12.0.min.js"></script>
        <script type="text/javascript" src="${base}/js/jquery.cxhd.js"></script>
        <script type="text/javascript" src="${base}/js/angular-base.js"></script>
        <title>JSP Page</title>
    </head>

    <body ng-app="auth" style="font-family: 微软雅黑;padding-top: 10px;background-color: #ffffff" ng-controller="mainCtrl">

        <div class="col-lg-12">
            <div class="panel panel-default ">
                <div class=" panel-heading">
                    <strong><span class="glyphicon glyphicon-th"></span>网络门诊请求</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <!--                    <button  ng-click="showCreate()" style="margin: 0px;" class="btn btn-default btn-round btn-xs">
                                            <i class="fa fa-plus-circle"></i> 添加
                                        </button>-->

                    <button title="刷新"  ng-click="getAskList()" style="margin: 0px;" class="btn btn-default btn-round btn-xs">
                        <i class="fa fa-refresh"></i>&nbsp;&nbsp;刷新
                    </button>
                    <!--                    <button  class="btn btn-primary ">Extra Small</button>-->
                    <!--<button ng-click="showCreate()" class="btn m-b-xs btn-sm btn-success btn-addon" ng-click="saveInfo()"><i class="fa fa-plus-square"></i>添加</button>-->
                    <!--                    <button  class="btn btn-primary btn-r btn-fab"><i class="mdi mdi-plus"></i></button>-->

                    <!--<div style="clear: both"></div>-->
                </div>
                <table class="table">
                    <tr>
                        <th style="">序号</th>
                        <th>病人姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>电话</th>
                        <th>就诊医生</th>
                        <th>预约时间</th>
                        <th>联系人</th>
                        <th>联系电话</th>
                        <th>状态</th>
                        <th>备注</th>
                        <th>其他</th>
                    </tr>
                    <tr  ng-repeat="item in asklist">
                        <td ng-bind="$index"></td>
                        <td ng-bind="item.patient_name"></td>
                        <td ng-bind="item.sex"></td>
                        <td ng-bind="item.age"></td>
                        <td ng-bind="item.phone"></td>                              
                        <td ng-bind="item.recvicer_name"></td>
                        <td  ng-bind="item.appointment_time"></td>
                        <td  ng-bind="item.contact"></td>
                        <td  ng-bind="item.contact_phone"></td>
                        <td  ng-bind="item.status_name"></td>
                        <td style="width: 100px;overflow-x: hidden" title="{{item.description}}"  ng-bind="item.description"></td>
                        <td>

                    <buton title="查看申请单" class="btn btn-primary btn-xs" ng-click="viewDetail(item)">查看</buton>
                    <buton class="btn btn-primary btn-xs" ng-click="openRpt(item)">报告</buton>
                    <buton class="btn btn-danger btn-xs" ng-click="deleteItem(item)">删除</buton>
                    <buton title="视频" class="btn btn-success btn-xs" ng-click="openVideo(item)"><i class="fa fa-video-camera"></i></buton>
                    </td>
                    </tr>
                </table>
                <div class="panel-heading" style="margin: 0px;padding: 0px;padding-top: 5px;">
                    <div  style="text-align: center">                
                        <pagination ng-change="askPageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="ask.currentPage" items-per-page="ask.pageSize" total-items="ask.bigTotalItems" ng-model="ask.bigCurrentPage" max-size="ask.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                    </div>           
                </div>
            </div>

        </div>

        <div class="modal fade mode-x " role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog modal-lg " role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <!--                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title" id="gridSystemModalLabel">{{modalTitle}}</h4>-->
                    </div>
                    <div class="modal-body">
                        <form  name="users" id="users" onsubmit="return false;">
                            <table style="width: 100%" class="cx-table">
                                <tr>
                                    <td style="width: 80px;">病人姓名：</td>
                                    <td>
                                        <input ng-click="openPatientSearch()"  ng-model="data.patient_name" type="text" class="form-control" required="">
                                    </td>

                                    <td style="width: 80px;">预约时间:</td>
                                    <td>
                                        <input id="date-format" ng-model="data.appointment_time" type="text" class="form-control" required="">
                                    </td>

                                </tr>
                                <tr>
                                    <td>病历&nbsp;&nbsp;&nbsp;号:</td>
                                    <td>
                                        <input ng-model="data.patient_id" type="text" class="form-control" required="">
                                    </td>

                                    <td>接诊医生：</td>
                                    <td>
                                        <input ng-click="openDoctor()" ng-model="data.recvicer_name" type="text" class="form-control" required="">
                                    </td>


                                </tr>
                                <tr>
                                    <td>年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄:</td>
                                    <td>
                                        <input ng-model="data.age" type="text" class="form-control" >
                                    </td>

                                    <td>联系&nbsp;&nbsp;&nbsp;人：</td>
                                    <td>
                                        <input ng-model="data.contact" type="text" class="form-control" >
                                    </td>

                                </tr>
                                <tr>
                                    <td>性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别:</td>
                                    <td>
                                        <input ng-model="data.sex" type="text" class="form-control">
                                    </td>

                                    <td>联系电话：</td>
                                    <td>
                                        <input ng-model="data.contact_phone" type="text" class="form-control" >
                                    </td>

                                </tr>
                                <tr>
                                    <td>病人电话:</td>
                                    <td>
                                        <input ng-model="data.phone" type="text" class="form-control">
                                    </td>
                                    <td>医院名称:</td>
                                    <td>
                                        <input ng-model="data.hospital_name" type="text" class="form-control">
                                    </td>

                                </tr>
                                <tr>
                                    <td>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</td>
                                    <td colspan="3">
                                        <input ng-model="data.description" type="text" class="form-control">
                                    </td>
                                </tr>



                            </table>
                        </form>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button  ng-click="saveInfo()" ng-disabled="users.$invalid" type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;保存</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->





        <div class="modal fade mode-patient " role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog modal-lg  " role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <div style="width:320px; float: left;margin-left: 20px">
                            <input ng-keyup="enterKey($event)" ng-model="searchContent" placeholder="名字/病人ID"  class="form-control input-sm" />
                        </div>
                        <button ng-click="getList()" style="float: left" class="btn btn-success btn-round btn-xs">搜索</button>
                        <div style="clear: both"></div>
                    </div>
                    <div class="modal-body" style="height: 400px;overflow-y: auto">

                        <table style="width: 100%" class="table">
                            <tr>
                                <th style="">病历号</th>
                                <th style="width: 80px;">姓名</th>
                                <th>性别</th>
                                <th>年龄</th>
                                <th>时间</th>
                                <th>项目</th>
                                <th>医院</th>
                                <th>其他</th>
                            </tr>
                            <tr ng-click="select_one(item, $event)" ng-repeat="item in list">
                                <td ng-bind="item.host_id"></td>
                                <td ng-bind="item.name"></td>
                                <td ng-bind="item.sex"></td>
                                <td ng-bind="item.age"></td>
                                <td ng-bind="item.last_event_time"></td>
                                <td ng-bind="item.last_event_name"></td>
                                <td ng-bind="item.hos_name"></td>
                                <td><button class="btn btn-success btn-xs" ng-click="goPatientInfo(item)" >补全资料</button></td>
                            </tr>




                        </table>


                        <div  style="text-align: center">                
                            <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="page.currentPage" items-per-page="page.pageSize" total-items="page.bigTotalItems" ng-model="page.bigCurrentPage" max-size="page.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                        </div>                     


                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">关闭</button>
                        <button  ng-click="sureOne()"  type="button" class="btn btn-primary btn-sm"><span class="fa fa-save"></span>&nbsp;&nbsp;确定</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->



        <div class="modal fade mode-doctor " role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog  modal-lg " role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        医生列表
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <!--                        <div style="width:320px; float: left;margin-left: 20px">
                                                    <input ng-keyup="enterKey($event)" ng-model="searchContent" placeholder="名字/病人ID"  class="form-control input-sm" />
                                                </div>
                                                <button ng-click="getList()" style="float: left" class="btn btn-success btn-round btn-xs">搜索</button>
                                                <div style="clear: both"></div>-->
                    </div>
                    <div class="modal-body" style="height: 300px;overflow-y: auto">

                        <table style="width: 100%" class="table">
                            <tr>
                                <th style="">序号</th>
                                <th>名字</th>
                                <th>性别</th>
                                <!--                                <th>年龄</th>-->
                                <th>科室</th>
                                <th>职称</th>
                                <th>医院</th>
                                <th>其他</th>
                            </tr>
                            <tr  ng-repeat="item in doctors">
                                <td  ng-bind="$index"></td>
                                <td ng-bind="item.ch_name"></td>
                                <td ng-bind="item.gender"></td>
                                <td ng-bind="item.department_name"></td>
                                <td ng-bind="item.job_level_name"></td>                              
                                <td ng-bind="item.hospital_name"></td>
                                <td >

                                    <button style="margin: 0px;"  ng-click="selectDoctor(item)" class="btn btn-primary btn-round  btn-xs">
                                        <i style="font-size: 10px;" class="fa fa-heart"></i>
                                    </button>
                                </td>
                            </tr>




                        </table>                                    


                    </div>
                    <!--                    <div class="modal-footer">
                                            <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">关闭</button>
                                            <button  ng-click="sureOne()"  type="button" class="btn btn-primary btn-sm"><span class="fa fa-save"></span>&nbsp;&nbsp;确定</button>
                                        </div>-->
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
    </body>
</html>
<script>

    angular.module("auth", ['baseModule', 'ui.bootstrap'])
            .controller("mainCtrl", function ($scope, base) {

                $scope.data = {};


                var so = $scope;
                $scope.page = {currentPage: 1};
                so.setPage = function (pageNo) {
                    $scope.page.currentPage = pageNo;
                };
                so.pageChanged = function () {
                    so.getList();
                };
                so.page.maxSize = 10;
                so.page.bigTotalItems = 20;
                so.page.bigCurrentPage = 1;
                so.page.pageSize = 10;

//                *******************************************

                $scope.ask = {currentPage: 1};
                so.setAskPage = function (pageNo) {
                    $scope.ask.currentPage = pageNo;
                };
                so.askPageChanged = function () {
                    so.getAskList();
                };
                so.ask.maxSize = 10;
                so.ask.bigTotalItems = 20;
                so.ask.bigCurrentPage = 1;
                so.ask.pageSize = 10;

                $('#date-format').bootstrapMaterialDatePicker({format: 'YYYY-MM-DD HH:mm'});

                $scope.showCreate = function () {
                    $scope.data = {};
                    $(".mode-x").modal('show');
                }
                $scope.openPatientSearch = function () {
                    $('.mode-patient').modal('show');
                }
                $scope.enterKey = function (event) {
                    if (event.keyCode == 13) {
                        $scope.getList();
                    }

                }

                $scope.saveInfo = function () {
                    base.post("add/saveAsk", $scope.data).get(function (data) {
                        if (data == "true") {
                            steveAl("保存成功", 1000);
                            $(".mode-x").modal('hide');
                            $scope.data = {};
                            $scope.getAskList();
                        } else {
                            steveAl("保存失败", 1000);
                        }
                    });
                }
                $scope.getAskList = function () {
                    base.post("add/getAskList", {pageSize: so.ask.pageSize, currentPage: so.ask.currentPage}).get(function (data) {
                        if (data) {
                            so.asklist = data.list;
                            so.ask.bigTotalItems = data.totalRow;
                            for (var i in so.asklist) {
                                // console.log(so.asklist[i].status==0);
                                if (so.asklist[i].status == 0) {
                                    so.asklist[i].status_name = "等待接诊";
                                } else if (so.asklist[i].status == 1) {
                                    so.asklist[i].status_name = "接诊中..";
                                } else if (so.asklist[i].status == 2) {
                                    so.asklist[i].status_name = "已完成";
                                }

                            }
                        }
                    })
                }


                $scope.getList = function () {
                    base.post("add/getList", {searchContent: $scope.searchContent, pageSize: so.page.pageSize, currentPage: so.page.currentPage}).get(function (data) {
                        console.log(data);
                        if (data) {
                            so.list = data.list;
                            so.page.bigTotalItems = data.totalRow;

                        }

                    })
                };
                $scope.viewDetail = function (item) {

                    if (window.parent) {
                        window.parent.addNewTab({href: window.location.pathname + "/viewApply?ask_code=" + item.ask_code+"&type=create",
//                            icon: icon,
                            title: item.patient_name + "的申请单"})
                    } else {
                        window.open("add/viewApply?ask_code=" + item.ask_code);
                    }
                }
                $scope.editItem = function (item) {
                    if (item.status == 2) {
                        steveAl("已完成报告不能修改");
                    } else {
                        $scope.data = item;
                        $(".mode-x").modal('show');
                    }
                }
                $scope.select_one = function (item, event) {

                    event.stopPropagation();
                    var $this = event.target;
                    $(".bg-info").removeClass("bg-info");
                    $($this).parent().addClass("bg-info");
                    $scope.item = item;

                }
                $scope.sureOne = function () {
                    $scope.data.patient_name = $scope.item.name;
                    $scope.data.age = $scope.item.age;
                    $scope.data.sex = $scope.item.sex;
                    $scope.data.phone = $scope.item.phone;
                    $scope.data.patient_id = $scope.item.host_id;
                    $scope.data.contact = userInfo.ch_name;
                    $scope.data.sender_id = userInfo.uuid;
                    $scope.data.sender_name = userInfo.ch_name;
//                    $scope.data.recvicer_id = userInfo.uuid;
                    $scope.data.contact_phone = userInfo.phone;
                    $scope.data.hospital_name = $scope.item.hos_name;
                    $(".mode-patient").modal("hide");
                }
                $scope.selectDoctor = function (item) {
                    $scope.data.recvicer_id = item.uuid;
                    $scope.data.recvicer_name = item.ch_name;
                    $scope.data.recvicer_phone = item.phone;
                    $(".mode-doctor").modal("hide");
                }

                $scope.openDoctor = function () {
                    if ($scope.data.appointment_time) {
                        $(".mode-doctor").modal("show");
                        base.post("add/getDoctor", {date: $scope.data.appointment_time.split(" ")[0]}).get(function (data) {
                            if (data) {
                                $scope.doctors = data.data;
                            }
                        })
                    } else {
                        steveAl("请选择预约时间", 1000);
                    }
                }
                $scope.openRpt = function (item) {

                    if (item.report_pk) {

                        if (window.parent) {
                            window.parent.addNewTab({href: "${base}/patient/readRpt?report_pk=" + item.report_pk,
//                            icon: icon,
                                title: item.patient_name + "会诊报告单"})
                        } else {
                            window.open("${base}/patient/readRpt?report_pk=" + item.report_pk);
                        }

                    }
                }
                $scope.goPatientInfo = function (item) {
                    if (window.parent) {
                        window.parent.showPatientInfo(item.name);
                    }
                }
                $scope.openVideo = function (item) {
                   
//                     if (window.parent) {
//                            window.parent.addNewTab({href: config.videoUrl + item.pk,
////                            icon: icon,
//                                title: "与"+item.hospital_name+"视频中"})
//                        } else {
                           window.open(config.videoUrl + item.pk);
                       // }
                }
                $scope.deleteItem = function (item) {
                    if (item.status == 1) {
                        steveAl("就诊中不能删除");
                    } else if (item.status == 2) {
                        steveAl("已完成不能删除");
                    } else {
                        steveConfrim("确定删除吗", function () {
                            base.post("add/deleteItem", {pk: item.pk}).get(function (data) {
                                if (data == 'true') {
                                    steveAl("删除成功", 1000);
                                    $scope.getAskList();
                                } else {
                                    steveAl("就诊中或已完成报告不能删除", 1000);
                                }
                            })
                        })
                    }


                }
                var init = function () {
                    $scope.getAskList();
                    $scope.getList();
                    // $scope.getMenu();

                }
                init();

            })
</script>
